#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"

#include <string.h>
#include <stdlib.h>
#define DEV STR_DEV

char wmark_str[256] = {0};
int main()
{
    int fd;
    int cameraID, displayX, displayY, enable;
    int sub_str_len;
    char *sub_str;
    char strBuf[256] = {0};
    fd = open(DEV, O_RDWR);
    int ret;
    if (fd != - 1)
    {
        while (1)
        {
            printf("\n\n\n");
            read(fd, &wmark_str, sizeof(wmark_str));
            ret = sscanf(wmark_str, "cameraID=%d,x=%d,y=%d,enable=%d,str=%s",
                    &cameraID, &displayX, &displayY, &enable, strBuf);
            if (EOF == ret || strlen(wmark_str) == 0) {
                printf(". %d", strlen(wmark_str));
                continue;
            }
            sub_str = strstr(wmark_str, "str=");
            sub_str_len = strlen(sub_str);
            memcpy(strBuf, sub_str + sizeof("str=") - 1, sub_str_len - strlen("str="));

            printf("cameraID=%d\nx=%d\ny=%d\nenable=%d\nstr=%s\n",
                    cameraID, displayX, displayY, enable, strBuf);
            
        }
    }
    else
    {
        printf("device open failure\n");
    }
    return 0;
}
